<!DOCTYPE html>
<html>
<head>
        <title>Netty Websocket 时间服务器</title>
    　　<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script type="text/javascript">
    var socket;
    if(!window.WebSocket){
        window.WebSocket = window.MozWebSocket;
    }
    if(window.WebSocket){
        socket = new WebSocket("ws://localhost:8099/websocket");
        socket.onmessage = function(event){
            var ta = document.getElementById('responseText');
            ta.value = "";
            ta.value = event.data
        };
        socket.onopen = function(event){
            var ta = document.getElementById('responseText');
            ta.value = "打开WebSocket 服务正常，浏览器支持WebSocket!";
        };
        socket.onclose = function(event){
            var ta = document.getElementById('responseText');
            ta.value = "";
            ta.value = "WebSocket 关闭！";
        };
    } else {
        alert("抱歉！您的浏览器不支持WebSocket协议！");
    }

    function send(message){
        if(!window.WebSocket){
            return;
        }
        if(socket.readyState == WebSocket.OPEN){
            socket.send(message);
        }else{
            alert("连接没有建立成功！");
        }
    }

</script>
<form onsubmit="return false;">
    <h3>Netty最佳实践</h3>
    <p>Netty Websocket 时间服务器</p>
    <input type="text" name="message" value="输入任何文本..."/>
    <input type="button" value="发送 Websocket 请求消息" onclick="send(this.form,message.value)"/>
    <hr color="blur"/>
    <h3>服务端返回的应答消息</h3>
    <textarea id="responseText" style="width: 500px; height: 300px;"></textarea>
</form>
</body>

</html>